package com.eastidea.live.util;

import java.io.File;

import org.apache.commons.lang3.StringUtils;

public class FileUtil {

	public static boolean removeFile(String path) {
		File file = new File(path);
		boolean result = false;
		if (file.exists())
			result = file.delete();
		return result;
	}

	public static String getExtension(String fileName, String defExt) {
		if ((fileName != null) && (fileName.length() > 0)) {
			int i = fileName.lastIndexOf('.');

			if ((i > -1) && (i < (fileName.length() - 1))) {
				return fileName.substring(i + 1);
			}
		}
		return defExt;
	}

	public static String getFileName(String filePath) {
		if (StringUtils.isEmpty(filePath)) {
			return "";
		}
		return filePath.substring(filePath.lastIndexOf("/") + 1,
				filePath.length());
	}
}
